<?php

/**
 * FaqController is the default controller for this application
 */
class FaqController extends BrowseControllerBase {
	/**
	 * FaqDataService Object
	 *
	 * @var FaqDataService object
	 */
	private $faqDataService = null;
	
	/**
	 *
	 * Faq Category Data Service
	 * @var FaqCategoryDataService object
	 */
	private $faqCategoryDataService = null;
	
	/**
	 * Constructor of index
	 */
	public function __construct() {
		parent::__construct ();
		
		// Initialize FaqDataService
		$this->faqDataService = new FaqDataService ();
		$this->faqCategoryDataService = new FaqCategoryDataService ();
	}
	
	/**
	 * The "index" action is the default action for all controllers -- the
	 * landing page of the site.     *
	 * @return void
	 */
	public function indexAction() {
		$arrElement = array ();
		$arrElement ['status'] = FaqCategoryEntity::ACTIVE;
		$arrElement ['parentId'] = 0;
		
		// Get Temlate Category
		$catList = $this->faqCategoryDataService->getItems ( $arrElement, " name " );
		$this->smarty->assign ( 'catList', $catList );
		$this->smarty->assign ( 'faqCategoryDataService', $this->faqCategoryDataService );
		$this->smarty->assign ( 'SMARTY_CONTENT_PATH', 'Browse/Faq/index.tpl' );
		$this->smarty->display ( APPLICATION_PATH . '/Layouts/Browse/MainLayout.tpl' );
	}
	
	/**
	 * List Questions of a Category
	 */
	public function listAction() {
		$catId = $this->getQuery ( 'catId', '' );
		if (empty ( $catId ) || ! is_numeric ( $catId )) {
			$this->listAction ();
		}
		
		// Get Category Details
		$categoryEntity = $this->faqCategoryDataService->getById ( $catId );
		
		// Get List Questions
		$itemList = $this->faqDataService->getAllTopicByCategory ( $catId, NULL, " question " );
		
		$this->smarty->assign ( 'categoryItem', $categoryEntity );
		$this->smarty->assign ( 'itemList', $itemList );
		$this->smarty->assign ( 'SMARTY_CONTENT_PATH', 'Browse/Faq/question_list.tpl' );
		$this->smarty->display ( APPLICATION_PATH . '/Layouts/Browse/MainLayout.tpl' );
	}
}
